import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/getParam")
public class ParamServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        String age = req.getParameter("age");

        resp.setContentType("text/html;charset=utf-8");
        if (Integer.parseInt(age)<1){
            resp.getWriter().write("婴儿");
        }else {
            resp.getWriter().write("其他");
        }

        System.out.println("name:"+name+",age:"+age);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        String age = req.getParameter("age");

        resp.getWriter().write("name:"+name+",age:"+age);
    }
}
